package cn.yq.aio.data;

import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;

import androidx.fragment.app.FragmentManager;

import cn.yq.aio.base.MyApp;

/**
 * @todo sp保存简单数据
 */
public class MySp {
    private static MySp instance = new MySp();
    private SharedPreferences sp;

    private MySp() {
        sp = MyApp.getInstance().getSharedPreferences("myInfo", Context.MODE_PRIVATE);
    }

    public static MySp getInstance() {
        return instance;
    }

    public String getValue(String key) {
        return sp.getString(key, "");
    }

    public String getValue(String key, String defValue) {
        return sp.getString(key, defValue);
    }

    public void setValue(String key, String value) {
        sp.edit().putString(key, value).apply();
    }


    public static final String USER_TOKEN = "token";

    public boolean isLogin() {
        return !TextUtils.isEmpty(sp.getString(USER_TOKEN, ""));
    }
}